package com.sr.examination.user;

import android.content.Context;

import com.sr.examination.user.base.LoginActivity;
import com.tl.commonlibrary.ui.beans.User;

/**
 * @author JongSung
 * @Description 账户管理类
 * 主要非UI逻辑实现见 {@link com.tl.commonlibrary.ui.user.Account}
 * 管理用户相关信息，是否登录，注销等操作
 * @date 2017/6/23 0022
 */
public class Account {
    public static User getUser() {
        return com.tl.commonlibrary.ui.user.Account.getUser();
    }

    public static void setUser(User newUser) {
        com.tl.commonlibrary.ui.user.Account.setUser(newUser);
    }

    public static boolean isLogged() {
        return com.tl.commonlibrary.ui.user.Account.isLogged();
    }

    public static boolean isNotLogged() {
        return com.tl.commonlibrary.ui.user.Account.isNotLogged();
    }

    public static boolean isNotLogged(Context context) {
        return isNotLogged(context, null);
    }

    public static boolean isNotLogged(Context context, String loginName) {
        boolean isNotLoggedIn = isNotLogged();
        if (isNotLoggedIn) {
            LoginActivity.start(context, loginName);
        }
        return isNotLoggedIn;
    }

    public static boolean isLogged(Context context) {
        return !isNotLogged(context);
    }


    public static void forceLogin(Context context) {
        forceLogin(context, null);
    }

    public static void forceLogin(Context context, String loginName) {
        if (isLogged()) {
            Account.logOff();
        }
        isNotLogged(context, loginName);
    }

    public static String getMobile() {
        if (getUser() != null) {
            return getUser().getMobile();
        }
        return "";
    }


    public static void logOff() {
        com.tl.commonlibrary.ui.user.Account.logOff();
    }
}
